package com.turing.post.datatranfer.impl;

import java.util.List;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.turing.post.datatranfer.util.EntityCard;
import com.turing.post.datatranfer.util.EntityCardDao;

/**
 * 实体卡库存接口实现
 * 
 * @author ZXL
 * 
 */
@Stateless(mappedName = "datatranfer.impl.EntityCardDaoImpl")
@Remote
@Local
public class EntityCardDaoImpl implements EntityCardDao {
	/**
	 * 实体管理器
	 */
	@PersistenceContext
	protected EntityManager _em;

	@SuppressWarnings("unchecked")
	@Override
	public List<EntityCard> getEntityCardList(String number) {
		String sql = "select * from EntityCard where substr(cardseqno,11,12) = ?1 order by CardSeqNo,CardNo desc ";
		Query query = _em.createNativeQuery(sql, EntityCard.class);
		query.setParameter(1, number);
		return query.getResultList();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Object[]> getSaleCardList(String startDate, String endDate) {
		String sql = "select t.batchno,t.cardstartseqno,t.cardcount,t.frombranchno,t.customid,c.cardparvalue,c.cardkindid,cardendseqno from cardinoutregister t,cardcontrol c where t.tradtime>=to_date('"
				+ startDate
				+ "','yyyy-mm-dd') and t.tradtime<to_date('"
				+ endDate + "','yyyy-mm-dd') and t.batchno=c.batchno";
		System.out.println(sql);
		Query query = _em.createNativeQuery(sql);
		List<Object[]> s = query.getResultList();
		System.out.println("===========" + s.size());
		return s;
	}
}
